﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FATCATool
{
    public partial class PoolReportControl : UserControl
    {
        CorrectablePoolReport_Type _poolReport;
        TreeNode _treeNode;

        public PoolReportControl()
        {
            InitializeComponent();
        }

        public void Intitalize(CorrectablePoolReport_Type poolReport, TreeNode treeNode)
        {
            _poolReport = poolReport;
            _treeNode = treeNode;
            DataBind();
            docSpecControl.Intitalize(_poolReport.DocSpec);
        }

        private void DataBind()
        {
            try
            {
                numPoolAmount.Value = Convert.ToDecimal(_poolReport.PoolBalance.Value);
            }
            catch { }

            try
            {
                numAccountCount.Value = Convert.ToDecimal(_poolReport.AccountCount);
            }
            catch { }

            var poolType = _poolReport.AccountPoolReportType;
            cmbPoolType.DataBindings.Clear();
            cmbPoolType.DataSource = FATCA_OECD.GetFriendlyEnumList(typeof(FatcaAcctPoolReportType_EnumType));
            cmbPoolType.ValueMember = "Key";
            cmbPoolType.DisplayMember = "Value";
            cmbPoolType.DataBindings.Add("SelectedItem", _poolReport, "AccountPoolReportType");
            cmbPoolType.SelectedValue = poolType;

            cmbCurrency.DataBindings.Clear();
            cmbCurrency.DataSource = Enum.GetValues(typeof(currCode_Type));
            cmbCurrency.DataBindings.Add("SelectedItem", _poolReport.PoolBalance, "currCode");

        }

        private void numPoolAmount_ValueChanged(object sender, EventArgs e)
        {
            _poolReport.PoolBalance.Value = numPoolAmount.Value;
        }

        private void numAccountCount_ValueChanged(object sender, EventArgs e)
        {
            _poolReport.AccountCount = numAccountCount.Value.ToString();
        }

        private void cmbPoolType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbPoolType.SelectedItem != null)
            {
                _poolReport.AccountPoolReportType = (FatcaAcctPoolReportType_EnumType)cmbPoolType.SelectedValue;
                _treeNode.Text = "Pool Report - " + FATCA_OECD.GetFriendlyEnumName(_poolReport.AccountPoolReportType);
            }
        }
    }
}
